/**
 *
 */
package com.angel.data.generator.comparators;

import java.util.Comparator;

import com.angel.data.generator.base.DataClassGenerator;

/** This comparator is used for sort all data class generator with dependencies order. The order depends on data class generator dependencies.
 * If a data class generator doesn't contains dependences it will be first. Then if another one has a dependencie with other data class generator, it will be
 * last becuase to generate its data first it must generate the dependence data.
 *
 * @author William
 *
 */
public class DataClassGeneratorDependencesDescComparator implements Comparator<DataClassGenerator>{

	public int compare(DataClassGenerator o1, DataClassGenerator o2) {
		int result = -2;
		if(o1 != null && o2 != null){
			if(o1.getDataGeneratorClass().equals(o2.getDataGeneratorClass())){
				result = 0;
			}
			if(result == -2) {
				boolean dependsOn = o1.dependsOn(o2.getDataGeneratorClass());
				if(dependsOn){
					result = -1;
				} else {
					result = 1;
				}
			}
		} else {
			if(o1 != null){
				result = 1;
			} else {
				result = -1;
			}
		}
		return result;
	}


}
